import { observable, action } from 'mobx';
import { RouterStore } from 'mobx-react-router';
import ComponentStore from './ComponentStore';

import { Toast } from 'antd-mobile';

export default class AuthStore {

    @observable phoneNum: string = '';
    @observable password: string = '';
    @observable isLogin: boolean = false;

    @action.bound
    async toLogin(routingStore: RouterStore, componentStore: ComponentStore) {
        if (!this.password || !this.phoneNum) {
            Toast.fail('请填写登录信息', 1);
        } else {
            componentStore.toastFlag = true;
            await setTimeout(() => {
                             componentStore.toastFlag = false;
                             Toast.success('登录成功', 1);
                             componentStore.currentTab = 'home';
                             routingStore.push('/home');
                             this.isLogin = true; },
                             1000);
        }
    }
    @action.bound
    // tslint:disable-next-line:no-empty
    async apiTest(url: string, params: object = {}) {
    }

    @action.bound
    setPhoneNum(num: string): void {
        this.phoneNum = num;
    }
    @action.bound
    setPassword(psw: string): void {
        this.password = psw;
    }
}